package com.luojilab.componentservice;

import android.app.Application;

import com.luojilab.componentservice.prefs.Preferences;
import com.then.basic.socket.data.CommClasses;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import javax.inject.Inject;
import javax.inject.Singleton;

import timber.log.Timber;

/**
 * Created by 42524 on 2018/2/5.
 */
@Singleton
public class GlobalEventManager {

    private Preferences preferences;

    private Application application;

    @Inject
    GlobalEventManager(Preferences preferences, Application application) {
        this.preferences = preferences;
        this.application = application;
        EventBus.getDefault().register(this);
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessage(CommClasses.LoginLoginServerInfo info) {
        int status = info.success;
        Timber.d("登录成功：" + info.userId);
        if (status == 0) { // 登录成功
            preferences.setUserId(info.userId + "");
        }
    }

}
